package cn.edu.zju.oms.container;

import com.github.kfcfans.powerjob.common.utils.NetUtils;
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
import com.github.kfcfans.powerjob.worker.core.processor.TaskContext;
import com.github.kfcfans.powerjob.worker.core.processor.TaskResult;
import com.github.kfcfans.powerjob.worker.core.processor.sdk.BroadcastProcessor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * ContainerBroadcastProcessor
 *
 * @author tjq
 * @since 2020/5/17
 */
@Component
public class ContainerBroadcastProcessor extends BroadcastProcessor {

    @Override
    public ProcessResult preProcess(TaskContext context) throws Exception {
        System.out.println("ContainerBroadcastProcessor#preProcess");
        context.getOmsLogger().info("start to preProcess, current worker IP is {}.", NetUtils.getLocalHost());
        return new ProcessResult(true, "pre success");
    }

    @Override
    public ProcessResult postProcess(TaskContext context, List<TaskResult> taskResults) throws Exception {
        System.out.println("ContainerBroadcastProcessor#postProcess");
        context.getOmsLogger().info("start to postProcess, current worker IP is {}.", NetUtils.getLocalHost());
        return new ProcessResult(true, "post success");
    }

    @Override
    public ProcessResult process(TaskContext taskContext) throws Exception {
        System.out.println("ContainerBroadcastProcessor#process");
        taskContext.getOmsLogger().info("start to process, current worker IP is {}.", NetUtils.getLocalHost());
        return new ProcessResult(true, "process success");
    }
}
